package utils
{
	import com.greensock.TweenMax;
	
	import data.MonsterProp;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.utils.ByteArray;

	public class GameUtils
	{
	
		public static function destoyEvent(event:Event):void
		{
			event.target.removeEventListener(event.type,arguments.callee);
		}
		
		public static function depthCopeObj(o:Object):Object{
			var byteArray:ByteArray = new ByteArray();
			byteArray.writeObject(o);
			byteArray.position = 0;
			var obj:Object = byteArray.readObject();
			return obj;
		}
		
		/**
		 * 获得x方向和y方向速度值
		 * @param p1 起始点
		 * @param p2 结束点
		 * @param speed 速度
		 * @return 
		 * 
		 */
		public static function getSpeed(p1:Point,p2:Point,speed:int):Point{
			var radian:Number = Math.atan2(p2.y - p1.y,p2.x - p1.x);
			return new Point(Math.cos(radian)*speed, Math.sin(radian)*speed);
		}
	
		public static function getTwoPointDistance(p1:Point,p2:Point):int{
			return Math.sqrt(Math.pow(p2.x - p1.x,2)+Math.pow(p2.y - p1.y,2));
		}
		/**
		 * 获得旋转角度 
		 * @param p1 自己坐标
		 * @param p2 目标点坐标
		 * @return 
		 * 
		 */		
		public static function getRotation(p1:Point,p2:Point):int{
			return Math.atan2(p2.y - p1.y,p2.x - p1.x)*180/Math.PI;
		}
		
		public static function setGrayFiler(dis:DisplayObject):void{
			TweenMax.to(dis,0,{alpha:1,colorMatrixFilter:{saturation:0}});
		}
		
		public static function clearGrayFiler(dis:DisplayObject):void{
			TweenMax.to(dis,0,{alpha:1,colorMatrixFilter:{saturation:1}});
		}
	}
}